import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
# 使用 bar()绘制三天中三部电影的票房变化
real_names = ['千与千寻', '玩具总动员 4', '黑衣人：全球追缉']
day1 = [5453, 7548, 6543]
day2 = [1840, 4013, 3421]
day3 = [1080, 1673, 2342]

x = np.arange(3)
x_label = ['第{}天'.format(i + 1) for i in x]
width = 0.3
plt.bar(x, day1, width=width, color='r', label=real_names[0])
plt.bar([i + width for i in x], day2, width=width, color='g', label=real_names[1])
plt.bar([i + 2 * width for i in x], day3, width=width, color='b', label=real_names[2])
plt.xticks([i + width for i in x], x_label)
# 添加图例
plt.legend()
# 添加标题
plt.title('3 天的票房数')

plt.show()

